package com.leyou.search.web;

import com.leyou.search.entity.Goods;
import com.leyou.search.service.SearchService;
import com.leyou.search.vo.GoodsRequestBodyVo;
import com.leyou.starter.elastic.entity.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/goods")
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 自动补全的自动名
     * @param key
     * @return
     */
    @GetMapping("/suggestion")
    public Mono<List<String>> querySuggestion(@RequestParam("key") String key) {

        return searchService.querySuggestion(key);
    }

    /**
     * 分页搜索商品数据
     * @param goodsRequestBodyVo
     * @return
     */
    @PostMapping("/list")
    public Mono<PageInfo<Goods>> queryPageInfoByGoods(
            @RequestBody GoodsRequestBodyVo goodsRequestBodyVo
    ) {
        return searchService.queryPageInfoByGoods(goodsRequestBodyVo);
    }

    /**
     * 根据商品数据，构建页面搜索条件
     * @return
     */
    @PostMapping("/filter")
    public Mono<Map<String,List<?>>> queryAggregationByGoods(
            @RequestBody GoodsRequestBodyVo goodsRequestBodyVo
    ) {
        return searchService.queryAggregationByGoods(goodsRequestBodyVo);
    }
}
